package com.zjj.spring.read.xml.factorybean.factory;

import org.springframework.beans.factory.FactoryBean;

/**
 * 实现spring的工厂Bean接口，实例化bean时会自动调用getObject()方法，返回值就是bean了
 * 
 * @author zhuangjiajie778
 *
 */
public class MyCarFactoryBean implements FactoryBean<Car>{
    private String name; 

    public Car getObject(){ 
      // 这里我们假设 Car 的实例化过程非常复杂，反正就不是几行代码可以写完的那种
      CarBuilder cb = CarBuilder.builder();
      cb.setName(name);
      return cb.factory(); 
    }

    public Class<Car> getObjectType() { return Car.class ; } 

    public boolean isSingleton() { return false; }
    
    public void setName(String name){ this.name = name ; }
}